<template>
  <div>

  <el-button type="text" @click="dialogFormVisible = true">登录</el-button>
  <el-dialog title="登录" :visible.sync="dialogFormVisible">
    <el-form :model="userlog">
      <el-form-item label="邮箱账户" :label-width="formLabelWidth">
        <el-input v-model="userlog.userEmail" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="账号密码" :label-width="formLabelWidth">
        <el-input v-model="userlog.userPassword" autocomplete="off" type="password"></el-input>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="login()">确 定</el-button>
    </div>
  </el-dialog>

<!--注册-->
    <el-button type="text" @click="dialogFormVisibleregin = true">注册</el-button>
    <el-dialog title="注册" :visible.sync="dialogFormVisibleregin">
      <el-form :model="userregist">

        <el-form-item label="注册的邮箱" prop="userEmail">
          <el-input style="width: 270px;" v-model="userregist.userEmail"></el-input>
          <el-tooltip class="item" effect="dark" content="点击发送验证码验证邮箱" placement="top-start">
            <el-button  type="info" @click="getcode()" icon="el-icon-message" circle></el-button>
          </el-tooltip>
        </el-form-item>

        <el-form-item label="验证码" prop="userCode">
          <el-input type="number" v-model="userregist.userCode" autocomplete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibleregin = false">取 消</el-button>
        <el-button type="primary" @click="regist()">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
  import axios from 'axios'
    export default {
        data() {
          return {
            userlog: {},
            dialogFormVisible: false,
            dialogFormVisibleregin: false,
            userregist: {},
            formLabelWidth:''
          }
        },
      methods:{
        login(){
          axios.post("http://localhost/kd-user/user/login",this.userlog).then(res=>{
            console.log(res.data.code)
            if (res.data.code==200){
              this.$message({
                type: 'success',
                message: '登录成功!'

              });
              this.dialogFormVisible=false;
              this.$cookie.set("token",res.data.data)
            } else{
              this.$message({
                type: 'warning',
                message: '登录失败!'
              });
            }
          })
        },
        regist(){
          axios.post("http://localhost/kd-user/user/regist",this.userregist).then(res=>{

            alert(res.data.code);
            if (res.data.code==200){
              this.$message({
                type: 'success',
                message: '注册成功!'
              });
              this.dialogFormVisibleregin=false;
            } else{
              this.$message({
                type: 'warning',
                message: '注册失败!'
              });
            }
          })
        },
        getcode() {
          axios.post("http://localhost/kd-user/user/sendcode", {userEmail: this.userregist.userEmail}).then(res => {
            if (res.data.code == 200) {

              this.$message({
                message:res.data.message,
                type: 'success'
              });
            } else {
              this.$message.error(res.data.message);
            }
          })
        },




          }



}



</script>

<style scoped>

</style>
